package com.hsq.androidproject.ui.recommend_fragment.rTv;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;

import com.example.lenovo.androidproject3.R;
import com.hsq.androidproject.adapter.MyrtvdetailsAdapter;
import com.hsq.androidproject.entity.rtvdetails;
import com.hsq.androidproject.utils.OkHttpClientManager;
import com.google.gson.Gson;
import com.squareup.okhttp.Request;


import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class DramaFragment extends Fragment {
    String url;
    private GridView gv_drama;

    public DramaFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_drama, container, false);
        initView(view);
        Bundle bundle = getArguments();                 ///////rtvActivity
        String sid = bundle.getString("id");
        url = "http://api.hanju.koudaibaobao.com/api/series/detailV3?sid=" + sid;           ////clejUj5Wase2Z10LeGyo
        ///http://api.hanju.koudaibaobao.com/api/series/detailV3?sid=clejUj5Wase2Z10LeGyo

        OkHttpClientManager.getAsyn(url, new OkHttpClientManager.ResultCallback<String>() {
            @Override
            public void onError(Request request, Exception e) {

            }

            @Override
            public void onResponse(String response) {
                rtvdetails rtvdetails1 = new Gson().fromJson(response, rtvdetails.class);
                List<rtvdetails.PlayItemsBean> playItemsBean = rtvdetails1.getPlayItems();
                MyrtvdetailsAdapter adapter = new MyrtvdetailsAdapter(playItemsBean, getContext());
                gv_drama.setAdapter(adapter);
            }
        });

        return view;
    }

    private void initView(View view) {
        gv_drama = (GridView) view.findViewById(R.id.gv_drama);
    }
}
